package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InfoUser;
import com.ruoyi.system.service.IInfoUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 坐席用户Controller
 * 
 * @author ruoyi
 * @date 2025-04-30
 */
@Controller
@RequestMapping("/system/userInfo")
public class InfoUserController extends BaseController
{
    private String prefix = "system/userInfo";

    @Autowired
    private IInfoUserService infoUserService;

    @RequiresPermissions("system:userInfo:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/userInfo";
    }

    /**
     * 查询坐席用户列表
     */
    @RequiresPermissions("system:userInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InfoUser infoUser)
    {
        startPage();
        List<InfoUser> list = infoUserService.selectInfoUserList(infoUser);
        return getDataTable(list);
    }

    /**
     * 导出坐席用户列表
     */
    @RequiresPermissions("system:userInfo:export")
    @Log(title = "坐席用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InfoUser infoUser)
    {
        List<InfoUser> list = infoUserService.selectInfoUserList(infoUser);
        ExcelUtil<InfoUser> util = new ExcelUtil<InfoUser>(InfoUser.class);
        return util.exportExcel(list, "坐席用户数据");
    }

    /**
     * 新增坐席用户
     */
    @RequiresPermissions("system:userInfo:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存坐席用户
     */
    @RequiresPermissions("system:userInfo:add")
    @Log(title = "坐席用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InfoUser infoUser)
    {
        return toAjax(infoUserService.insertInfoUser(infoUser));
    }

    /**
     * 修改坐席用户
     */
    @RequiresPermissions("system:userInfo:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") String userId, ModelMap mmap)
    {
        InfoUser infoUser = infoUserService.selectInfoUserByUserId(userId);
        mmap.put("infoUser", infoUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存坐席用户
     */
    @RequiresPermissions("system:userInfo:edit")
    @Log(title = "坐席用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InfoUser infoUser)
    {
        return toAjax(infoUserService.updateInfoUser(infoUser));
    }

    /**
     * 删除坐席用户
     */
    @RequiresPermissions("system:userInfo:remove")
    @Log(title = "坐席用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(infoUserService.deleteInfoUserByUserIds(ids));
    }
}
